<div id="painel_interno">
    <div id="menu_topo">
        <div class="postmetadataheader">
            <h2 class="postheader">Gerenciador de sorteios.</h2>
        </div>
        <div id="menu">
            <ul>
                <li><?= anchor('admin/sorteios/insert', 'Adicionar', array('class' => 'ui-button botao')) ?></li>
                <li><?= anchor('admin/index', 'Fechar', array('class' => 'ui-button botao')) ?></li>
            </ul>
        </div>
    </div>
    <div id="modo">
    <?php
        switch (@$modo):
        default:
            ?>
            <div id="grid">
                <table border="0" width="100%" align="center" id="grid">
                    <thead>
                        <tr>
<!--                            <th class="ui-widget-header">Codigo</th>-->
                            <th class="ui-widget-header">Anuciantes</th>
                            <th class="ui-widget-header">Titulo Sorteio</th>
<!--                            <th class="ui-widget-header">Descricao</th>
                            <th class="ui-widget-header">Regras</th>-->
                            <th class="ui-widget-header">Foto</th>
                            <th class="ui-widget-header">Dt. Sorteio</th>
                            <th class="ui-widget-header">Prorr. Auto</th>
                            <th class="ui-widget-header">Sorteio Nulo?</th>
                            <th class="ui-widget-header">Qnt. Ativação</th>
                            <th class="ui-widget-header">Modalidade</th>
                            <th class="ui-widget-header">Dt. Cadastro</th>
                            <th class="ui-widget-header">Ref. CEF</th>
                            <th class="ui-widget-header">Resultado CEF</th>
<!--                            <th class="ui-widget-header">id_gahador</th>-->
                            <th class="ui-widget-header">Valor do Bilhete</th>
                            <th class="ui-widget-header">Status</th>
                            <th class="ui-widget-header" width="60">Ação</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($lista as $row): ?>
                            <tr>
    <!--                                <td valign="middle"><?= $row->idsorteios; ?></td>-->
                                <td valign="middle"><?= relacionamento('anunciantes', 'idanunciantes', 'nome', $row->idanunciantes, 'text'); ?></td>
                                <td valign="middle"><?= $row->titulo_sorteio; ?></td>
<!--                                <td valign="middle"><?= $row->descricao; ?></td>
                                <td valign="middle"><?= $row->regras; ?></td>-->
                                <td valign="middle">
                                  <?php if($row->foto){ ?>
                                <img src="<?=site_url();?>/admin/imagem/thumbs/midia-sorteios/<?= $row->foto; ?>/50/50" />
                                <?php } ?></td> 
                                <td valign="middle"><?= mdate('%d/%m/%Y', strtotime($row->data_sorteio)); ?></td>
                                <td valign="middle"><?= sim_nao($row->prorrogacao_automatica); ?></td>
                                <td valign="middle"><?= sim_nao($row->permite_sorteio_nulo); ?></td>
                                <td valign="middle"><?= $row->minimo_ativacao; ?></td>
                                <td valign="middle"><?= $row->modalidade; ?></td>
                                <td valign="middle"><?= mdate('%d/%m/%Y', strtotime($row->data_cadastro)); ?></td>
                                <td valign="middle"><?= $row->referencia_cef; ?></td>
                                <td valign="middle"><?= $row->resultado_cef; ?></td>
<!--                                <td valign="middle"><?= $row->id_gahador; ?></td>-->
                                <td valign="middle">R$ <?= number_format($row->valor,2,",","."); ?></td>
                                <td valign="middle"><?= sim_nao( $row->status ); ?></td>
                                <td valign="middle">
                                    <ul>
                                        <li class="ui-state-default ui-corner-all" title="Alterar">
                                            <?= anchor('admin/sorteios/update/' . $row->idsorteios, 'Alterar', array('class' => 'ui-icon ui-icon-pencil')); ?>
                                        </li>
                                        <li class="ui-state-default ui-corner-all" title="Excluir">
                                            <?= anchor('admin/sorteios/delete/' . $row->idsorteios, 'Apagar', array('class' => 'ui-icon ui-icon-trash', 'onclick' => 'return apagar()')); ?>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
                <div id="resumo">
                    <span class="total">Total de <b><?= $total_registros; ?></b> registros.</span>
                    <span class="box_paginacao">
                        <?= $paginacao; ?>
                    </span>
                </div>
            </div>
            <?php
            break;
        case 'insert':
            ?>
            <form name="form_insert" action="<?= site_url('admin/sorteios/save/'); ?>" method="POST" enctype="multipart/form-data" class="ui-widget-content">
                <table border="0" width="100%" align="center" class="ui-widget" id="table_form">
                    <thead>
                        <tr>
                            <th></th>
                            <th></th>
                        </tr>
                     </thead>
                     <tbody>
                         <tr>
                                     <td>Anuciantes</td>
                                     <td>
                                         <select name="idanunciantes" id="idanunciantes" class="form_input" >
                                             <?php foreach (relacionamento('anunciantes', 'idanunciantes', 'nome', '', 'form') as $rel): ?>
                                                 <option value="<?= $rel->idanunciantes; ?>"
                                                     <?php if ($row->idanunciantes == $rel->idanunciantes)
                                                        echo 'selected'; ?>>
                                                     <?= $rel->nome; ?>
                                                 </option>
                                         <?php endforeach; ?>
                                         </select>
                                     </td>
                                 </tr>
                         <tr>
                             <td>Titulo Sorteio</td>
                             <td><input type="text" name="titulo_sorteio" value="<?= $row->titulo_sorteio; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Descricao</td>
                             <td><input type="text" name="descricao" value="<?= $row->descricao; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Regras</td>
                             <td><input type="text" name="regras" value="<?= $row->regras; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Foto</td>
                             <td><input type="file" name="userfile" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Dt. Sorteio</td>
                             <td><input type="text" name="data_sorteio" value="<?= mdate('%d/%m/%Y', strtotime($row->data_sorteio)); ?>" size="45" class="form_input data" /></td>
                         </tr>
                         <tr>
                             <td>Prorr. Auto</td>
                             <td> <input type="checkbox"  value="1"  name="prorrogacao_automatica" <?= marcado($row->prorrogacao_automatica); ?>  /></td>
                         </tr>
                         <tr>
                             <td>Sorteio Nulo?</td>
                             <td><input type="checkbox"  value="1"  name="permite_sorteio_nulo" <?= marcado($row->permite_sorteio_nulo); ?>  /></td>
                         </tr>
                         <tr>
                             <td>Qnt. Ativação</td>
                             <td><input type="text" name="minimo_ativacao" value="<?= $row->minimo_ativacao; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Modalidade</td>
                             <td><input type="text" name="modalidade" value="<?= $row->modalidade; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Dt. Cadastro</td>
                             <td><input type="text" name="data_cadastro" value="<?= mdate('%d/%m/%Y', strtotime($row->data_cadastro)); ?>" size="45" class="form_input data" /></td>
                         </tr>
                         <tr>
                             <td>Ref. CEF</td>
                             <td><input type="text" name="referencia_cef" value="<?= $row->referencia_cef; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Resultado CEF</td>
                             <td><input type="text" name="resultado_cef" value="<?= $row->resultado_cef; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Valor do Bilhete</td>
                             <td>R$ <input type="text" name="valor" value="<?= $row->valor; ?>" size="45" class="form_input" /></td>
                         </tr>
<!--                         <tr>
                             <td>id_gahador</td>
                             <td><input type="text" name="id_gahador" value="<?= $row->id_gahador; ?>" size="45" class="form_input" /></td>
                         </tr>-->
                           <tr>
                             <td>Status</td>
                             <td><input type="checkbox"  value="1"  name="status" <?= marcado($row->status); ?>  /></td>
                         </tr>
                         <tr>
                             <td></td>
                             <td>
                                 <input type="submit" value="Salvar" name="bot_salvar" class="ui-button botao" />
                                 <?= anchor('admin/sorteios', 'Cancelar'); ?>
                             </td>
                         </tr>
                     </tbody>
                 </table>
             </form>
             <?php
             break;
         case 'update':
             ?>
             <form name="form_update" action="<?= site_url('admin/sorteios/save/' . $row->idsorteios); ?>" method="POST" enctype="multipart/form-data" class="ui-widget-content">
                 <table border="0" width="100%" align="center" class="ui-widget" id="table_form">
                     <thead>
                         <tr>
                             <th></th>
                             <th></th>
                         </tr>
                     </thead>
                     <tbody>
                         <tr>
                                     <td>Anuciantes</td>
                                     <td>
                                         <select name="idanunciantes" id="idanunciantes" class="form_input" >
                                             <?php foreach (relacionamento('Anunciantes', 'idanunciantes', 'nome', '', 'form') as $rel): ?>
                                                 <option value="<?= $rel->idanunciantes; ?>"
                                                     <?php if ($row->idanunciantes == $rel->idanunciantes)
                                                        echo 'selected'; ?>>
                                                     <?= $rel->nome; ?>
                                                 </option>
                                         <?php endforeach; ?>
                                         </select>
                                     </td>
                                 </tr>
                         <tr>
                             <td>Titulo Sorteio</td>
                             <td><input type="text" name="titulo_sorteio" value="<?= $row->titulo_sorteio; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Descricao</td>
                             <td><input type="text" name="descricao" value="<?= $row->descricao; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Regras</td>
                             <td><input type="text" name="regras" value="<?= $row->regras; ?>" size="45" class="form_input" /></td>
                         </tr>
                        <tr>
                             <td>Foto</td>
                             <td><input type="file" name="userfile" size="45" class="form_input" /> <label><input type="checkbox" name="alterar_arquivo" value="1" /> Alterar a foto.</label></td>
                         </tr>
                         <tr>
                             <td>Dt. Sorteio</td>
                             <td><input type="text" name="data_sorteio" value="<?= mdate('%d/%m/%Y', strtotime($row->data_sorteio)); ?>" size="45" class="form_input data " /></td>
                         </tr>
                         <tr>
                             <td>Prorr. Auto</td>
                             <td> <input type="checkbox"  value="1"  name="prorrogacao_automatica" <?= marcado($row->prorrogacao_automatica); ?>  /></td>
                         </tr>
                         <tr>
                             <td>Sorteio Nulo?</td>
                             <td><input type="checkbox"  value="1"  name="permite_sorteio_nulo" <?= marcado($row->permite_sorteio_nulo); ?>  /></td>
                         </tr>
                         <tr>
                             <td>Qnt. Ativação</td>
                             <td><input type="text" name="minimo_ativacao" value="<?= $row->minimo_ativacao; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Modalidade</td>
                             <td><input type="text" name="modalidade" value="<?= $row->modalidade; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Dt. Cadastro</td>
                             <td><input type="text" name="data_cadastro" value="<?= mdate('%d/%m/%Y', strtotime($row->data_cadastro)); ?>" size="45" class="form_input data" /></td>
                         </tr>
                         <tr>
                             <td>Ref. CEF</td>
                             <td><input type="text" name="referencia_cef" value="<?= $row->referencia_cef; ?>" size="45" class="form_input" /></td>
                         </tr>
                         <tr>
                             <td>Resultado CEF</td>
                             <td><input type="text" name="resultado_cef" value="<?= $row->resultado_cef; ?>" size="45" class="form_input" /></td>
                         </tr>
<!--                         <tr>
                             <td>id_gahador</td>
                             <td><input type="text" name="id_gahador" value="<?= $row->id_gahador; ?>" size="45" class="form_input" /></td>
                         </tr>-->
                          <tr>
                             <td>Valor do Bilhete</td>
                             <td>R$ <input type="text" name="valor" value="<?= $row->valor; ?>" size="45" class="form_input" /></td>
                         </tr>
                           <tr>
                             <td>Status</td>
                             <td><input type="checkbox"  value="1"  name="status" <?= marcado($row->status); ?>  /></td>
                         </tr>
                         <tr>
                             <td></td>
                             <td>
                                 <input type="submit" value="Salvar" name="bot_salvar" class="ui-button botao" />
                                 <?= anchor('admin/sorteios', 'Cancelar'); ?>
                             </td>
                         </tr>
                     </tbody>
                 </table>
             </form>
            <?php
        endswitch;
        ?>
    </div>
</div>
